﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Plugin.Archives.Service;
using RsCms.Application.Posts.Dto;

namespace Plugin.Archives.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class ArchivesController : ControllerBase
    {
        ArchiveAppService archiveAppService;
        public ArchivesController(ArchiveAppService archiveAppService)
        {
                this.archiveAppService = archiveAppService;
        }

		[Authorize]
		[HttpGet("detail")]
		public async Task<object> GetDetailAsync(string id)
		{
			return await archiveAppService.GetArchiveByTitleOrIdAsync(id);
		}

		[Authorize]
        [HttpGet("list")]
        public async Task<object>PageArchiveAsync(int page,int pageSize, string date = null) 
		{
			return await archiveAppService.PageArchiveAsync(page, pageSize, date);
		}


		[Authorize]
		[HttpPost("edit")]
		public async Task<object> SavePostsAsync([FromBody] PostEditDto dto)
		{
			return await archiveAppService.SaveAsync(dto);
		}
		[Authorize]
		[HttpPost("delete")]
		public async Task<object> DeletePostsAsync(string id)
		{
			await archiveAppService.DeleteArchiveAsync(id);
			return "ok";
		}
	}
}



